package org.cptz.game.controller;

import org.cptz.game.constant.EnumConst;
import org.cptz.game.dto.ResultDto;
import org.cptz.game.entity.Player;
import org.cptz.game.service.IPlayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 玩家 前端控制器
 * </p>
 *
 * @author cpt.z
 * @since 2022-08-07
 */
@RestController
@RequestMapping("/player")
public class PlayerController {

    @Autowired
    private IPlayerService playerService;


    @PostMapping("/save")
    public ResultDto save(@RequestBody Player player) {
        playerService.save(player);
        return new ResultDto(EnumConst.RespCode.SUCCESS);
    }

    @PostMapping("/login")
    public ResultDto login(@RequestBody Player player) {
        Player playerDb = playerService.getById(player.getId());
        return new ResultDto(EnumConst.RespCode.SUCCESS, playerDb.getPassword().equals(player.getPassword()));
    }


}
